home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vbdatabs
/
int32.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-14
|
16KB
|
737 lines
// ------------------------------- //
// -------- Start of File -------- //
// ------------------------------- //
// ----------------------------------------------------------- //
// C++ Source Code File Name: int32.cpp
// Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
// Produced By: Doug Gaer
// File Creation Date: 09/05/1997
// Date Last Modified: 03/15/1999
// Copyright (c) 1997 Douglas M. Gaer
// ----------------------------------------------------------- //
// ------------- Program Description and Details ------------- //
// ----------------------------------------------------------- //
/*
The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
All those who put this code or its derivatives in a commercial
product MUST mention this copyright in their documentation for
users of the products in which this code or its derivative
classes are used. Otherwise, you have the freedom to redistribute
verbatim copies of this source code, adapt it to your specific
needs, or improve the code and release your improvements to the
public provided that the modified files carry prominent notices
stating that you changed the files and the date of any change.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
CORRECTION.
The INT32 class is used to represent 32 bit signed integers
independently of the operating system or hardware platform
used. It was created to overcome the big and little endian
problem encountered when writing integer values to a common
database file accessed by several different types of machines.
The INT32 class is used to represent 32 bit signed integers
independently of the operating system or hardware platform used.
It works by separating a 32-bit value into four separate byte
values and reordering the bytes lowest-order to highest-order.
An INT32 type has a base 10 positive limit of 2,147,483,647 and
a negative limit of 2,147,483,648.
*/
// ----------------------------------------------------------- //
#include <string.h>
#include <memory.h>
#include "int32.h"
#include "ehandler.h"
INT32::INT32(__LWORD__ val)
{
UnPackBits(val);
}
INT32::INT32(const INT32& ob)
{
memmove((void *)byte, (const void *)ob.byte, 4);
}
INT32& INT32::operator=(const INT32& ob)
{
memmove((void *)byte, (const void *)ob.byte, 4);
return *this;
}
INT32& INT32::operator=(const __LWORD__ val)
{
UnPackBits(val);
return *this;
}
INT32::operator __LWORD__() const
{
return PackBits();
}
__LWORD__ INT32::PackBits() const
{
__LWORD__ a, b, c, d;
a = (__LWORD__)byte[0];
b = (__LWORD__)byte[1];
c = (__LWORD__)byte[2];
d = (__LWORD__)byte[3];
a = a & 0xFF;
b = (b<<8) & 0xFF00;
c = (c<<16) & 0xFF0000;
d = (d<<24) & 0xFF000000;
return a + b + c + d;
}
void INT32::UnPackBits(__LWORD__ val)
{
byte[0] = val & 0xFF;
byte[1] = (val & 0xFF00)>>8;
byte[2] = (val & 0xFF0000)>>16;
byte[3] = (val & 0xFF000000)>>24;
}
INT32 INT32::operator++(int) // Postfix
{
INT32 val_before(*this);
operator=(*this + 1);
return val_before;
}
INT32 INT32::operator--(int) // Postfix
{
INT32 val_before(*this);
operator=(*this - 1);
return val_before;
}
void INT32::operator/=(const INT32 &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __LWORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __ULWORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __WORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __SWORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __UWORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __USWORD__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / i);
}
void INT32::operator/=(const __SBYTE__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / (__LWORD__)i);
}
void INT32::operator/=(const __UBYTE__ &i)
{
if(i == 0)
#ifdef CPP_EXCEPTIONS
throw CDivideByZero();
#else
Error->SignalException(EHandler::DivideByZero);
#endif
operator=(*this / (__LWORD__)i);
}
int operator==(const INT32 &a, const INT32 &b)
{
return a.PackBits() == b.PackBits();
}
int operator==(const INT32 &a, const __LWORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __LWORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __ULWORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __ULWORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __WORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __WORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __SWORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __SWORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __UWORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __UWORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __USWORD__ &bl)
{
return a.PackBits() == bl;
}
int operator==(const __USWORD__ &al, const INT32 &b)
{
return al == b.PackBits();
}
int operator==(const INT32 &a, const __SBYTE__ &bl)
{
return a.PackBits() == (__LWORD__)bl;
}
int operator==(const __SBYTE__ &al, const INT32 &b)
{
return (__LWORD__)al == b.PackBits();
}
int operator==(const INT32 &a, const __UBYTE__ &bl)
{
return a.PackBits() == (__LWORD__)bl;
}
int operator==(const __UBYTE__ &al, const INT32 &b)
{
return (__LWORD__)al == b.PackBits();
}
int operator!=(const INT32 &a, const INT32 &b)
{
return a.PackBits() != b.PackBits();
}
int operator!=(const INT32 &a, const __LWORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __LWORD__ &al, const INT32 &b)
{
return al != b.PackBits();
}
int operator!=(const INT32 &a, const __ULWORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __ULWORD__ &al, const INT32 &b)
{
return al != b.PackBits();
}
int operator!=(const INT32 &a, const __WORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __WORD__ &al, const INT32 &b)
{
return al != b.PackBits();
}
int operator!=(const INT32 &a, const __SWORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __SWORD__ &al, const INT32 &b)
{
return al != b.PackBits();
}
int operator!=(const INT32 &a, const __UWORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __UWORD__ &al, const INT32 &b)
{
return al != b.PackBits();
}
int operator!=(const INT32 &a, const __USWORD__ &bl)
{
return a.PackBits() != bl;
}
int operator!=(const __USWORD__ &al, const INT32 &b)
{
return al != b.PackBi